import React from "react";
import {
  FileTextOutlined,
  BookOutlined,
  UserOutlined,
  BarChartOutlined,
  CheckCircleOutlined,
  ClockCircleOutlined,
  TrophyOutlined,
  MessageOutlined,
  SettingOutlined,
  SecurityScanOutlined,
  LineChartOutlined,
} from "@ant-design/icons";

// 路由路径配置
export const ROUTES = {
  // 管理员路由
  ADMIN: {
    HOME: "/admin",
    DASHBOARD: "/admin/dashboard",
    USERS: "/admin/users",
    TEACHERS: "/admin/teachers",
    STUDENTS: "/admin/students",
    COURSES: "/admin/courses",
    SETTINGS: "/admin/settings",
    REPORTS: "/admin/reports",
    AI_MONITORING: "/admin/ai-monitoring",
  },

  // 教师路由
  TEACHER: {
    HOME: "/teacher",
    COURSES: "/teacher/courses",
    PREPARATION: "/teacher/preparation",
    CLASS_MANAGEMENT: "/teacher/class-management",
    EXAM_GENERATION: "/teacher/exam-generation",
    EXAM_GRADING: "/teacher/exam-grading", // 新增考试批阅路径
    HOMEWORK_GRADING: "/teacher/homework-grading", // 作业批改路径
    LEARNING_ANALYSIS: "/teacher/learning-analysis",
    RESOURCES: "/teacher/resources",
    DISCUSSIONS: "/teacher/discussions",
    EXAMS: {
      LIST: "/teacher/exams",
      REVIEW: "/teacher/exams/review",
      CREATE: "/teacher/exams/create",
    },
    ANALYSIS: {
      STUDENTS: "/teacher/analysis/students",
      COURSES: "/teacher/analysis/courses",
      PERFORMANCE: "/teacher/analysis/performance",
    },
  },

  // 学生路由
  STUDENT: {
    HOME: "/student",
    COURSES: "/student/courses",
    HOMEWORK: "/student/homework",
    EXAMS: "/student/exams",
    DISCUSSIONS: "/student/discussions",
    PROFILE: "/student/profile",
    LEARNING_ANALYSIS: "/student/learning-analysis",
  },

  // 通用路由
  COMMON: {
    LOGIN: "/login",
    REGISTER: "/register",
    PROFILE: "/profile",
    SETTINGS: "/settings",
  },
};

// 首页卡片配置
export const DASHBOARD_CARDS = {
  // 教师首页卡片
  TEACHER: {
    "exam-grading": {
      title: "考试批阅",
      description: "批阅学生考试提交",
      icon: <CheckCircleOutlined />,
      path: ROUTES.TEACHER.EXAM_GRADING,
      color: "#52c41a",
      count: 0, // 动态数据
    },
    "pending-homework": {
      title: "作业批改",
      description: "查看和批改学生作业",
      icon: <FileTextOutlined />,
      path: ROUTES.TEACHER.HOMEWORK_GRADING,
      color: "#faad14",
      count: 0, // 动态数据
    },
    "exam-review": {
      title: "考试复查",
      description: "复查考试结果和统计",
      icon: <TrophyOutlined />,
      path: ROUTES.TEACHER.EXAMS.REVIEW,
      color: "#1890ff",
      count: 0,
    },
    "student-analysis": {
      title: "学生分析",
      description: "查看学生学习情况分析",
      icon: <BarChartOutlined />,
      path: ROUTES.TEACHER.ANALYSIS.STUDENTS,
      color: "#1890ff",
      count: 0,
    },
    "course-management": {
      title: "课程管理",
      description: "管理课程内容和进度",
      icon: <BookOutlined />,
      path: ROUTES.TEACHER.COURSES,
      color: "#722ed1",
      count: 0,
    },
    "class-overview": {
      title: "班级概览",
      description: "查看班级整体情况",
      icon: <UserOutlined />,
      path: ROUTES.TEACHER.CLASS_MANAGEMENT,
      color: "#eb2f96",
      count: 0,
    },
    discussions: {
      title: "讨论管理",
      description: "管理课程讨论和互动",
      icon: <MessageOutlined />,
      path: ROUTES.TEACHER.DISCUSSIONS,
      color: "#13c2c2",
      count: 0,
    },
  },

  // 学生首页卡片
  STUDENT: {
    "my-courses": {
      title: "我的课程",
      description: "查看已选课程",
      icon: <BookOutlined />,
      path: ROUTES.STUDENT.COURSES,
      color: "#1890ff",
      count: 0,
    },
    "pending-homework": {
      title: "待完成作业",
      description: "查看和提交作业",
      icon: <FileTextOutlined />,
      path: ROUTES.STUDENT.HOMEWORK,
      color: "#faad14",
      count: 0,
    },
    "upcoming-exams": {
      title: "即将考试",
      description: "查看考试安排",
      icon: <TrophyOutlined />,
      path: ROUTES.STUDENT.EXAMS,
      color: "#52c41a",
      count: 0,
    },
    discussions: {
      title: "课程讨论",
      description: "参与课程讨论",
      icon: <MessageOutlined />,
      path: ROUTES.STUDENT.DISCUSSIONS,
      color: "#722ed1",
      count: 0,
    },
  },

  // 管理员首页卡片
  ADMIN: {
    "user-management": {
      title: "用户管理",
      description: "管理系统用户",
      icon: <UserOutlined />,
      path: ROUTES.ADMIN.USERS,
      color: "#1890ff",
      count: 0,
    },
    "course-overview": {
      title: "课程概览",
      description: "系统课程统计",
      icon: <BookOutlined />,
      path: ROUTES.ADMIN.COURSES,
      color: "#52c41a",
      count: 0,
    },
    "system-reports": {
      title: "系统报告",
      description: "查看系统统计报告",
      icon: <BarChartOutlined />,
      path: ROUTES.ADMIN.REPORTS,
      color: "#faad14",
      count: 0,
    },
    "system-settings": {
      title: "系统设置",
      description: "配置系统参数",
      icon: <SettingOutlined />,
      path: ROUTES.ADMIN.SETTINGS,
      color: "#722ed1",
      count: 0,
    },
  },
};

// 面包屑配置
export const BREADCRUMB_CONFIG: Record<
  string,
  { title: string; icon?: React.ReactNode }
> = {
  "/admin": { title: "管理后台", icon: <SettingOutlined /> },
  "/admin/dashboard": { title: "仪表板", icon: <BarChartOutlined /> },
  "/admin/users": { title: "用户管理", icon: <UserOutlined /> },
  "/admin/teachers": { title: "教师管理", icon: <UserOutlined /> },
  "/admin/students": { title: "学生管理", icon: <UserOutlined /> },
  "/admin/courses": { title: "课程管理", icon: <BookOutlined /> },
  "/admin/settings": { title: "系统设置", icon: <SettingOutlined /> },
  "/admin/reports": { title: "统计报告", icon: <BarChartOutlined /> },

  "/teacher": { title: "教师工作台", icon: <BookOutlined /> },
  "/teacher/courses": { title: "课程管理", icon: <BookOutlined /> },
  "/teacher/preparation": { title: "备课助手", icon: <FileTextOutlined /> },
  "/teacher/class-management": { title: "班级管理", icon: <UserOutlined /> },
  "/teacher/exam-generation": {
    title: "智能出题",
    icon: <CheckCircleOutlined />,
  },
  "/teacher/homework/grading": {
    title: "作业批改",
    icon: <FileTextOutlined />,
  },
  "/teacher/learning-analysis": {
    title: "学习分析",
    icon: <BarChartOutlined />,
  },
  "/teacher/resources": { title: "教学资源", icon: <FileTextOutlined /> },
  "/teacher/discussions": { title: "讨论区", icon: <MessageOutlined /> },
  "/teacher/exams": { title: "考试管理", icon: <TrophyOutlined /> },
  "/teacher/exams/review": { title: "考试复查", icon: <TrophyOutlined /> },
  "/teacher/exams/create": { title: "创建考试", icon: <TrophyOutlined /> },
  "/teacher/analysis/students": {
    title: "学生分析",
    icon: <BarChartOutlined />,
  },
  "/teacher/analysis/courses": {
    title: "课程分析",
    icon: <BarChartOutlined />,
  },
  "/teacher/analysis/performance": {
    title: "成绩分析",
    icon: <BarChartOutlined />,
  },

  "/student": { title: "学生中心", icon: <UserOutlined /> },
  "/student/courses": { title: "我的课程", icon: <BookOutlined /> },
  "/student/homework": { title: "作业管理", icon: <FileTextOutlined /> },
  "/student/exams": { title: "考试中心", icon: <TrophyOutlined /> },
  "/student/discussions": { title: "讨论区", icon: <MessageOutlined /> },
  "/student/profile": { title: "个人中心", icon: <UserOutlined /> },

  "/login": { title: "登录", icon: <UserOutlined /> },
  "/register": { title: "注册", icon: <UserOutlined /> },
  "/profile": { title: "个人资料", icon: <UserOutlined /> },
  "/settings": { title: "设置", icon: <SettingOutlined /> },
};

// 导航菜单配置
export const NAVIGATION_MENUS = {
  TEACHER: [
    {
      key: ROUTES.TEACHER.HOME,
      icon: <FileTextOutlined />,
      label: "首页",
    },
    {
      key: ROUTES.TEACHER.COURSES,
      icon: <BookOutlined />,
      label: "课程管理",
    },
    {
      key: ROUTES.TEACHER.PREPARATION,
      icon: <FileTextOutlined />,
      label: "备课助手",
    },
    {
      key: ROUTES.TEACHER.CLASS_MANAGEMENT,
      icon: <UserOutlined />,
      label: "班级管理",
    },
    {
      key: ROUTES.TEACHER.EXAM_GENERATION,
      icon: <CheckCircleOutlined />,
      label: "智能出题",
    },
    {
      key: ROUTES.TEACHER.EXAM_GRADING,
      icon: <CheckCircleOutlined />,
      label: "考试批阅",
    },
    {
      key: ROUTES.TEACHER.HOMEWORK_GRADING,
      icon: <FileTextOutlined />,
      label: "作业批改",
    },
    {
      key: ROUTES.TEACHER.LEARNING_ANALYSIS,
      icon: <BarChartOutlined />,
      label: "学习分析",
    },
    {
      key: ROUTES.TEACHER.RESOURCES,
      icon: <FileTextOutlined />,
      label: "教学资源",
    },
    {
      key: ROUTES.TEACHER.DISCUSSIONS,
      icon: <MessageOutlined />,
      label: "讨论区",
    },
  ],

  STUDENT: [
    {
      key: ROUTES.STUDENT.HOME,
      icon: <FileTextOutlined />,
      label: "首页",
    },
    {
      key: ROUTES.STUDENT.COURSES,
      icon: <BookOutlined />,
      label: "我的课程",
    },
    {
      key: ROUTES.STUDENT.HOMEWORK,
      icon: <FileTextOutlined />,
      label: "作业中心",
    },
    {
      key: ROUTES.STUDENT.EXAMS,
      icon: <TrophyOutlined />,
      label: "考试中心",
    },
    {
      key: ROUTES.STUDENT.LEARNING_ANALYSIS,
      icon: <LineChartOutlined />,
      label: "学习分析",
    },
    {
      key: ROUTES.STUDENT.DISCUSSIONS,
      icon: <MessageOutlined />,
      label: "讨论区",
    },
    {
      key: ROUTES.STUDENT.PROFILE,
      icon: <UserOutlined />,
      label: "个人中心",
    },
  ],

  ADMIN: [
    {
      key: ROUTES.ADMIN.HOME,
      icon: <BarChartOutlined />,
      label: "首页",
    },
    {
      key: ROUTES.ADMIN.DASHBOARD,
      icon: <BarChartOutlined />,
      label: "仪表板",
    },
    {
      key: ROUTES.ADMIN.USERS,
      icon: <UserOutlined />,
      label: "用户管理",
      children: [
        {
          key: ROUTES.ADMIN.TEACHERS,
          label: "教师管理",
        },
        {
          key: ROUTES.ADMIN.STUDENTS,
          label: "学生管理",
        },
      ],
    },
    {
      key: ROUTES.ADMIN.COURSES,
      icon: <BookOutlined />,
      label: "课程管理",
    },
    {
      key: ROUTES.ADMIN.AI_MONITORING,
      icon: <SecurityScanOutlined />,
      label: "AI监测",
    },
    {
      key: ROUTES.ADMIN.REPORTS,
      icon: <BarChartOutlined />,
      label: "统计报告",
    },
    {
      key: ROUTES.ADMIN.SETTINGS,
      icon: <SettingOutlined />,
      label: "系统设置",
    },
  ],
};

// 路由权限配置
export const ROUTE_PERMISSIONS = {
  // 管理员可访问的路由
  admin: [
    ...Object.values(ROUTES.ADMIN),
    ROUTES.ADMIN.AI_MONITORING,
    ROUTES.COMMON.PROFILE,
    ROUTES.COMMON.SETTINGS,
  ],

  // 教师可访问的路由
  teacher: [
    ...Object.values(ROUTES.TEACHER),
    ...Object.values(ROUTES.TEACHER.EXAMS),
    ...Object.values(ROUTES.TEACHER.ANALYSIS),
    ROUTES.COMMON.PROFILE,
    ROUTES.COMMON.SETTINGS,
  ],

  // 学生可访问的路由
  student: [
    ...Object.values(ROUTES.STUDENT),
    ROUTES.STUDENT.LEARNING_ANALYSIS,
    ROUTES.COMMON.PROFILE,
    ROUTES.COMMON.SETTINGS,
  ],
};

// 辅助函数：获取卡片配置
export const getDashboardCards = (
  userRole: "admin" | "teacher" | "student"
) => {
  switch (userRole) {
    case "admin":
      return DASHBOARD_CARDS.ADMIN;
    case "teacher":
      return DASHBOARD_CARDS.TEACHER;
    case "student":
      return DASHBOARD_CARDS.STUDENT;
    default:
      return {};
  }
};

// 辅助函数：获取导航菜单
export const getNavigationMenu = (
  userRole: "admin" | "teacher" | "student"
) => {
  switch (userRole) {
    case "admin":
      return NAVIGATION_MENUS.ADMIN;
    case "teacher":
      return NAVIGATION_MENUS.TEACHER;
    case "student":
      return NAVIGATION_MENUS.STUDENT;
    default:
      return [];
  }
};

// 辅助函数：检查路由权限
export const hasRoutePermission = (
  userRole: "admin" | "teacher" | "student",
  path: string
) => {
  const permissions = ROUTE_PERMISSIONS[userRole] || [];
  return permissions.includes(path);
};

// 辅助函数：获取面包屑
export const getBreadcrumbItems = (pathname: string) => {
  const pathParts = pathname.split("/").filter(Boolean);
  const breadcrumbItems = [];

  let currentPath = "";
  for (const part of pathParts) {
    currentPath += `/${part}`;
    const config = BREADCRUMB_CONFIG[currentPath];
    if (config) {
      breadcrumbItems.push({
        path: currentPath,
        title: config.title,
        icon: config.icon,
      });
    }
  }

  return breadcrumbItems;
};
